package com.suqiu.qqrobot.common.exception;

import com.suqiu.qqrobot.common.result.IResultCode;
import com.suqiu.qqrobot.common.result.ResultCodeEnum;
import lombok.Getter;

/**
 * @author: suqiu
 * @desc: 业务异常处理
 * @date: 2023/4/18
 */
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = -344010746099480622L;

    @Getter
    private final IResultCode resultCode;


    /**
     * 建议使用该方法,明确指定具体的业务异常code和message
     *
     * @param resultCode
     */
    public BusinessException(IResultCode resultCode) {
        super(resultCode.getMessage());
        this.resultCode = resultCode;
    }

    public BusinessException(IResultCode resultCode, Throwable cause) {
        super(cause);
        this.resultCode = resultCode;
    }

    /**
     * 通用异常, 返回FAILURE, 但其message可以注入自定义方式
     *
     * @param msg
     */
    public BusinessException(String msg) {
        super(msg);
        this.resultCode = ResultCodeEnum.FAILURE;
    }
}
